package com.usian.controller;

import com.usian.mapper.CommodityMapper;
import com.usian.pojo.Commodity;
import com.usian.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.SpinnerUI;
import java.util.List;

@Controller
@RequestMapping("commodity")
public class CommodityController {
    @Autowired
    private CommodityService commodityService;


    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Commodity> list = commodityService.findAll();
        model.addAttribute("list",list);
        return "ass";
    }

    @RequestMapping("/toadd")
    public String toadd(){
        return "add";
    }


    @PostMapping("/add1")
    String add( Commodity commodity){
        commodityService.add(commodity);
        return "redirect:/commodity/findAll";
    }


    @RequestMapping("/del")
    public String del(Integer pid){
        commodityService.del(pid);
        return "redirect:/commodity/findAll";
    }

    @RequestMapping("/updateById")
    public String updateById(Commodity commodity){
        commodityService.updateById(commodity);
        return "redirect:/commodity/findAll";
    }
}
